﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasertTemplates.Master" AutoEventWireup="true"
    CodeBehind="WebLogin.aspx.cs" Inherits="WebApplication.WebLogin" %>

<%@ Register TagPrefix="uc1" TagName="usermeg" Src="~/UserControl/UserMessageControl.ascx" %>
<%@ Register TagPrefix="uc1" TagName="maintab" Src="~/UserControl/MainTabControl.ascx" %>
<%@ Register TagPrefix="uc1" TagName="Paginator" Src="~/UserControl/PaginatorUC.ascx" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript" src="Media/Js/jquery.query.js"></script>
    <script type="text/javascript" src="media/js/jquery-ui-1.8.10.custom.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            //--排序图标初始化------------
            OrderImg();
            //--分页的跳转 页码初始化------------
            JumpPageInit();
        })

        var custid = '<%=CustomerID%>';
        var custuid = '<%=CustomerUID %>';
        function submit() {
            var addorupdate = $('#ContentPlaceHolder2_hfAddOrUpdate').val();
            if (addorupdate == 'add') {
                Add();
            }
            else {
                if (addorupdate != null || addorupdate != '') {
                    Update(addorupdate.split('&')[1]);
                }
            }
        }

        function Add() {
            $("#ContentPlaceHolder2_lblMessages").html("程序处理中...");
            var name = $('#ContentPlaceHolder2_txtLoginID').val();
            var status = $('#ContentPlaceHolder2_ddlStatus').val();

            if (name == null || name == '') { $("#ContentPlaceHolder2_lblMessages").html("请输入完整信息"); return; }

            $.ajax({
                url: "ServerAshxFile/WebLogin.ashx?type=1&name=" + name + "&status=" + status + "&custuid=" + custuid,
                type: "POST",
                error: function () {
                    $("#ContentPlaceHolder2_lblMessages").html("程序内部出错...");
                },
                success: function (data) {
                    var flag = data.split('&');
                    if (flag[0] > 0) {
                        $("#timeTable tbody").prepend(flag[1]);
                        $("#tr_" + flag[0]).effect("pulsate", { times: 2 }, 400);
                        $("#ContentPlaceHolder2_lblMessages").html("添加成功！");
                    }
                    else if (flag[0] == -1) {
                        $("#ContentPlaceHolder2_lblMessages").html("Login ID已经存在.");
                    }
                    else {
                        $("#ContentPlaceHolder2_lblMessages").html("程序出错！");
                    }
                }
            });
        }

        function Update(webloginUID) {
            $("#ContentPlaceHolder2_lblMessages").html("程序处理中...");
            var name = $('#ContentPlaceHolder2_txtLoginID').val();
            var status = $('#ContentPlaceHolder2_ddlStatus').val();
            if (name == null || name == '') { $("#ContentPlaceHolder2_lblMessages").html("请输入完整信息"); return; }
            $.ajax({
                url: "ServerAshxFile/WebLogin.ashx?type=2&name=" + name + "&status=" + status + "&custuid=" + custuid + "&webloginUID=" + webloginUID,
                type: "POST",
                error: function () {
                    $("#ContentPlaceHolder2_lblMessages").html("程序内部出错...");
                },
                success: function (data) {
                    var flag = data.split('&');
                    if (flag[0] > 0) {
                        //alert(flag[1]);
                        $("#tr_" + flag[0]).html(flag[1]);
                        $("#tr_" + flag[0]).effect("pulsate", { times: 2 }, 400);
                        $("#ContentPlaceHolder2_lblMessages").html("修改成功！");
                    }
                    else {
                        $("#ContentPlaceHolder2_lblMessages").html("修改没有成功！");
                    }
                }
            });
        }

        function Edit(webloginUID) {
            $.get("ServerAshxFile/WebLogin.ashx", { 'type': '3', 'webloginUID': webloginUID }, function (data) {
                if (data != null || data != '') {
                    var uid = data.split('&')[0];
                    var name = data.split('&')[1];
                    var status = data.split('&')[2];

                    $('#ContentPlaceHolder2_txtLoginID').val(name);
                    $('#ContentPlaceHolder2_ddlStatus').val(status);
                    $('#ContentPlaceHolder2_hfAddOrUpdate').val("update&" + uid)
                    $("#ContentPlaceHolder2_lblMessages").html("");
                    $("#SearchForm").css('display', 'block');
                    $("#a_add_update").html("Modify");
                }
            });
        }

        function Quit() {
            $("#SearchForm").css('display', 'none');
            $('#ContentPlaceHolder2_hfAddOrUpdate').val('add');
            $("#ContentPlaceHolder2_lblMessages").html("");

            $('#ContentPlaceHolder2_txtLoginID').val('');
            $('#ContentPlaceHolder2_ddlStatus').val('1');
        }

        function Toggle_Add() {
            //ToggleDocument('SearchForm');

            $('#ContentPlaceHolder2_hfAddOrUpdate').val('add');
            $("#ContentPlaceHolder2_lblMessages").html("");

            if (custid != '') {
                $('#ContentPlaceHolder2_txtLoginID').val(custid + create_ramdom());
            }
            $('#ContentPlaceHolder2_ddlStatus').val('1');
            $("#a_add_update").html("Add");
            $("#SearchForm").css('display', 'block');
        }

        //--排序--------
        function OrderBy(property_file) {
            var pageName = "WebLogin.aspx";
            var new_params = '';
            var orderby = $.query.get("ob");
            if (orderby == 'desc') {
                new_params = $.query.set('pp', property_file).set("ob", 'asc');
            }
            else {
                new_params = $.query.set('pp', property_file).set("ob", 'desc');
            }
            window.location.href = pageName + new_params;
        }
        //--排序结束

        //--排序图标
        function OrderImg() {
            var pp = $.query.get('pp');
            var ob = $.query.get('ob');
            if (ob == 'desc') {
                $('#a_' + pp).parent('.hw').parent('th').addClass('headerSortUp').removeClass('headerSortDown');
            }
            else {
                $('#a_' + pp).parent('.hw').parent('th').addClass('headerSortDown').removeClass('headerSortUp');
            }
        }
        //--排序图标结束

        //--分页的跳转 页码初始化------------
        function JumpPageInit() {
            $("#ContentPlaceHolder2_paginator1_txtCur,#ContentPlaceHolder2_paginator2_txtCur").blur(function () {
                var jumpCount = 1;
                var maxCount = $("#ContentPlaceHolder2_paginator1_lblTotalPages").html();
                if (parseInt($(this).val()) > parseInt(maxCount)) {
                    jumpCount = maxCount;
                    $(this).val(maxCount);
                }
                else {
                    jumpCount = $(this).val();
                }
                var newUrl = $.query.set("page", jumpCount).toString();
                $("#ContentPlaceHolder2_paginator1_hyGo").attr("href", newUrl);
                $("#ContentPlaceHolder2_paginator2_hyGo").attr("href", newUrl);
            });
        }
        //--分页的跳转结束------------

        //生成一位（范围：1-9）整数的随机数
        function create_ramdom() {
            var vNum;
            vNum = Math.random();
            vNum = Math.round(vNum * 10) + 1;
            if (vNum == 10) {
                vNum - 1;
            }
            return vNum;
        }
        //--生成随机数结束

        function SetWebLoginUID(webloginUID) {
            $("#hd_webloginUID").val(webloginUID);
            $("#sendemail_messages").html("");      
        }

        function SendEmailToCP() {
            if (custuid != '') {
                webloginUID = $("#hd_webloginUID").val();
                var send_email ='';
                var input_list = $("#tb_SendEmailBox tr td input");

                $.each(input_list, function () {
                    if ($(this).attr('checked') == true) {
                        send_email += $(this).val()+";";
                    }
                });
                if (send_email == '') {
                    $("#sendemail_messages").html("请选择要发送的账号.");
                    return;
                }


                $.ajax({
                    url: "ServerAshxFile/WebLogin.ashx?type=10&custuid=" + custuid + "&webloginUID=" + webloginUID + "&send_email=" + send_email,
                    type: "POST",
                    error: function () {
                        $("#sendemail_messages").html("程序内部出错...");
                    },
                    success: function (data) {
                        if (data=='1') {
                            $("#sendemail_messages").html("邮件发送成功！");
                        }
                        else {
                            $("#sendemail_messages").html("邮件发送失败！");
                        }
                    }
                });

            }                     
        }

    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <input type="hidden" value="t4" id="pageName" />
    <div class="content-title">
        <h1>
            Customer - WebLogin</h1>
    </div>
    <div class="con-nav">
        <a href="Basicinformation.aspx" class="btn"><span class="ui-icon ui-icon-newwin"></span>
            Add New Customer</a>
    </div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
    <uc1:usermeg ID="usermeg" runat="server"></uc1:usermeg>
    <ajaxToolkit:ToolkitScriptManager EnablePartialRendering="true" runat="Server" ID="ScriptManager1" />
    <div class="partWrap">
        <uc1:maintab ID="maintab" runat="server" />
        <div class="clear10">
        </div>
        <ul class="uibtn">
            <li onclick="javascript:Toggle_Add();"><span>Add Web Login</span></li>
        </ul>
        <div class="clear10">
        </div>
        <div id="SearchForm" class="SearchForm">
            <table width="500" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td>
                        <p class="upinput">
                            Login ID <span class="red">*</span>
                        </p>
                        <asp:TextBox ID="txtLoginID" runat="server" CssClass="input200"></asp:TextBox>
                    </td>
                    <td>
                        <p class="upinput">
                            Login ID Status<span class="red">*</span>
                        </p>
                        <asp:DropDownList ID="ddlStatus" runat="server" CssClass="select200">
                            <asp:ListItem Value="1" Text="Active"></asp:ListItem>
                            <asp:ListItem Value="2" Text="Inactive"></asp:ListItem>
                        </asp:DropDownList>
                    </td>
                </tr>
                <tr>
                    <td colspan="2" height="10">
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <table border="0" cellspacing="0" cellpadding="0" class="btnwrap">
                            <tr>
                                <td class="btnwrapl">
                                    <ul class="uibtn">
                                        <li><a id="a_add_update" href="javascript:submit();">Save</a>
                                            <asp:HiddenField ID="hfAddOrUpdate" runat="server" Value="add" />
                                        </li>
                                    </ul>
                                </td>
                                <td class="btnwrapr">
                                    <ul class="uibtn">
                                        <li><a href="javascript:Quit()">Quit</a></li>
                                    </ul>
                                </td>
                                <td>
                                </td>
                            </tr>
                            <tr>
                                <td rowspan="3" class="btnwrapr">
                                    <asp:Label ID="lblMessages" runat="server" Text="" ForeColor="Red"></asp:Label>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </div>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true" UpdateMode="Always"
            RenderMode="Block">
            <ContentTemplate>
                <uc1:Paginator ID="paginator1" runat="server" />
                <div class="msgBoxPS">
                    <div class="SendEmailBox" id="SendBox">
                        <table width="100%" border="0">
                            <tr>
                                <td>
                                    <h4>
                                        <img src="Media/Css/images/del-select.png" class="closeBtn" onclick="ToggleDocument('SendBox');"
                                            alt="" /><strong>Send Remind Password Email</strong></h4>        
                                            <input type="hidden" id="hd_webloginUID" />                               
                                    <br />
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <table id="tb_SendEmailBox" width="100%" border="0" cellspacing="0" cellpadding="0">
                                        <asp:Literal ID="ltlSendEmailBox" runat="server"></asp:Literal>                                        
                                        <%--<tr>
                                            <td>
                                                <input type="checkbox"><label for="">Contact person name Attribute Email
                                                </label>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <input type="checkbox"><label for="">Contact person name Attribute Email
                                                </label>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <input type="checkbox"><label for="">Contact person name Attribute Email
                                                </label>
                                            </td>
                                        </tr>--%>
                                    </table>
                                </td>
                            </tr>
                            <tr>
                                <td height="10">
                                <span id="sendemail_messages" style="color:Green;"></span>
                                </td>
                            </tr>
                        </table>
                        <table border="0" cellspacing="0" cellpadding="0" class="btnwrap">
                            <tr>
                                <td class="btnwrapl">
                                    <ul class="uibtn">
                                        <li><a href='javascript:SendEmailToCP();'>Send Email</a></li>
                                    </ul>
                                </td>
                                <td class="btnwrapr">
                                    <ul class="uibtn">
                                        <li  onclick="ToggleDocument('SendBox')"><span>Quit</span></li>
                                    </ul>
                                </td>
                                <td>
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
                <div class="table-wrap">
                    <table width="100%" border="0" background="#cccccc" cellspacing="1" cellpadding="0"
                        class="listing-table" id="timeTable">
                        <thead>
                            <tr>
                                <th width="50" align="left">
                                    Index
                                </th>
                                <th>
                                    <div class="hw">
                                        <a id="a_LoginName" href='javascript:OrderBy("LoginName")'><span>Login ID</span></a>
                                        <span class="order-1"></span>
                                        <div class="dragDiv">
                                        </div>
                                    </div>
                                </th>
                                <th>
                                    <div class="hw">
                                        <a id="a_Status" href='javascript:OrderBy("Status")'><span>Login ID Status </span>
                                        </a><span class="order-1"></span>
                                        <div class="dragDiv">
                                        </div>
                                    </div>
                                </th>
                                <th>
                                    <div class="hw">
                                        <a id="a_CreationDate" href='javascript:OrderBy("CreationDate")'><span>Date</span></a><span
                                            class="order-1"></span><div class="dragDiv">
                                            </div>
                                    </div>
                                </th>
                                <th>
                                    &nbsp;
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            <asp:Repeater ID="Repeater1" runat="server">
                                <ItemTemplate>
                                    <tr id='<%#"tr_"+Eval("CustWebLoginUID") %>'>
                                        <td>
                                            <%# Container.ItemIndex +1%>
                                        </td>
                                        <td class="td2">
                                            <%#Eval("LoginName")%>
                                        </td>
                                        <td class="td3">
                                            <%#GetStatusString(Eval("Status"))%>
                                        </td>
                                        <td class="td1">
                                            <%#DateFormatString2(Eval("CreationDate"))%>
                                        </td>
                                        <td class="td9" width="160">
                                            <a href='javascript:Edit(<%#Eval("CustWebLoginUID") %>)'>Edit</a> | <a href='javascript:ToggleDocument("SendBox");SetWebLoginUID(<%#Eval("CustWebLoginUID") %>);'>
                                                Send Email</a>
                                        </td>
                                    </tr>
                                </ItemTemplate>
                            </asp:Repeater>
                        </tbody>
                    </table>
                </div>
                <uc1:Paginator ID="paginator2" runat="server" />
                </div>
            </ContentTemplate>
        </asp:UpdatePanel>
        <div id="space" style="margin-top:400px;">&nbsp;</div>
        <div id="Popconfirms" class="Popconfirms">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td align="center">
                        <div class="Poptxt">
                            您确定要删除吗？</div>
                    </td>
                </tr>
                <tr>
                    <td align="center">
                        <div class="clear20">
                        </div>
                        <table>
                            <tr>
                                <td>
                                    <ul class="uibtn">
                                        <li onclick="javascript:ToggleDocument('wrapToggle');return true;">Sure</li>
                                    </ul>
                                </td>
                                <td width="10">
                                </td>
                                <td>
                                    <ul class="uibtn">
                                        <li onclick="javascript:ToggleDocument('wrapToggle');return false;">Quit</li>
                                    </ul>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </div>
</asp:Content>
